﻿using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using MyFloridaHouse.DataAccess.Extensions;
using MyFloridaHouse.libSvDTO;

namespace MyFloridaHouse.DataAccess
{
    public partial class DAL_CensusData
    {

        /// <summary>
        /// Gets the region data.
        /// </summary>
        /// <param name="iLayerID">The ilayerID.</param>
        /// <param name="iRegionID">The iregionID.</param>
        /// <returns>List of <see cref="RegionDataNameAndValueDTO"/></returns>
        /// <remarks>SPROC: usp_moGetRegionData</remarks>
        public List<RegionDataNameAndValueDTO> GetRegionData(int iLayerID, int iRegionID)
        {
            List<RegionDataNameAndValueDTO> itemList = new List<RegionDataNameAndValueDTO>();

            //string storedProcedureName = "usp_moGetRegionData";
            string storedProcedureName = "usp_tl10GetRegionData10";

            using (SqlConnection db = Connect())
            {
                SqlCommand StoredProcedureCommand = new SqlCommand(storedProcedureName, db);
                StoredProcedureCommand.CommandType = CommandType.StoredProcedure;
                SqlParameter dataPartIDParm = StoredProcedureCommand.Parameters.AddWithValue("iLayerID", iLayerID);
                dataPartIDParm.Direction = ParameterDirection.Input;
                SqlParameter dataPartIDParm2 = StoredProcedureCommand.Parameters.AddWithValue("iRegionID", iRegionID);
                dataPartIDParm2.Direction = ParameterDirection.Input;


                db.Open();
                using (SqlDataReader rdr = StoredProcedureCommand.ExecuteReader())
                {
                    while (rdr.Read())
                    {
                        itemList.Add(RegionDataNameAndValueDTODataContract.DataContract(rdr));
                    }
                }
            }

            //Database db = Connect();
            ////DbCommand dbCommand = db.GetStoredProcCommand("usp_moGetRegionData");
            //DbCommand dbCommand = db.GetStoredProcCommand("usp_tl10GetRegionData10");
            //db.AddInParameter(dbCommand, "iLayerID", DbType.String, iLayerID);
            //db.AddInParameter(dbCommand, "iRegionID", DbType.String, iRegionID);
            //using (IDataReader rdr = db.ExecuteReader(dbCommand))
            //{
            //    while (rdr.Read())
            //    {
            //        itemList.Add(RegionDataNameAndValueDTODataContract.DataContract(rdr));

            //    }
            //}
            return itemList;
        }
    }
}
